﻿namespace Gp.Scripts.Core
{
    public class UnitOutlineRenderer
    {
        public bool IsHighlighted { get; private set; }
        private UnitOutlineState _outlineState;
        public UnitOutlineMode OutlineMode { get; private set; }
        private readonly UnitModel _model;
        public UnitOutlineRenderer(UnitModel model)
        {
            _model = model;
        }

        public void SetOutlineMode(UnitOutlineMode outlineMode)
        {
            if (outlineMode.GetType() == _outlineState?.GetType()) return;
            _outlineState = outlineMode.GetOutlineModeRenderer();
            _outlineState.Apply(_model);
            
            if (IsHighlighted) 
                _outlineState.TriggerHighlight();
            else 
                _outlineState.DisableHighlight();
        }

        public void TriggerHighlight()
        {
            _outlineState.TriggerHighlight();
        }

        public void DisableHighlight()
        {
            _outlineState.DisableHighlight();
        }
    }
}